﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;



//#if !UNITY_ANDROID
//#if !UNITY_IPHONE
//using System.Windows.Forms;
//#endif
//#endif

namespace QPDefine
{
    public class WinForm
    {
        //       public static WinForm instacne = new WinForm();
        //        public void CopyToClipboardIMG(string imgPath)
        //        {
        //#if !UNITY_ANDROID
        //#if !UNITY_IPHONE
        //            if (!File.Exists(imgPath)) { return; }
        //            //UnityEngine.Application.dataPath + "/onPcSavedScreen.png"
        //            byte[] bytes = File.ReadAllBytes(imgPath);
        //            MemoryStream stream = new MemoryStream(bytes);
        //            Clipboard.SetImage(System.Drawing.Image.FromStream(stream));
        //            stream.Close();
        //            stream.Dispose();
        //#endif
        //#endif
        //        }

        //       public IEnumerator CaptureScreenShot2(int width, int height, GameObject parent, string savePath = null, Camera camera = null, bool isCopy = false)
        //        {
        //            yield return new WaitForEndOfFrame();
        //            //先创建一个的空纹理，大小可根据实现需要来设置  
        //            Texture2D screenShot = new Texture2D(width, height, TextureFormat.RGB24, false);
        //            // 读取屏幕像素信息并存储为纹理数据，
        //            if (camera == null) { camera = Camera.current; }
        //            Vector2 v2 = camera.WorldToScreenPoint(parent.transform.position);
        //            int x = (int)v2.x;
        //            int y = (int)v2.y;
        //            //Debug.Log("x=" + (x - width / 2) + " y=" + (y - height / 2) + " width=" + (int)rect.width + " height=" + (int)rect.height);
        //            screenShot.ReadPixels(new Rect((x - width / 2), (y - height / 2), width, height), 0, 0);
        //            screenShot.Apply();
        //            // 然后将这些纹理数据，成一个png图片文件  
        //            byte[] bytes = screenShot.EncodeToPNG();
        //            if (savePath == null) { savePath = UnityEngine.Application.dataPath + "/Screenshot.png"; }
        //            if (File.Exists(savePath)) { File.Delete(savePath); }
        //            System.IO.File.WriteAllBytes(savePath, bytes);
        //            if (isCopy) { CopyToClipboardIMG(savePath); }
        //        }

        //        /// <summary>
        //        /// 截屏
        //        /// </summary>
        //        public void CaptureScreenShot(int width, int height, GameObject parent, string savePath, Camera camera)
        //        {
        //            parent.GetComponent<MonoBehaviour>().StartCoroutine(CaptureScreenShot2(width, height, parent, savePath, camera, false));
        //        }
        //        /// <summary>
        //        /// 截屏并且Copy
        //        /// </summary>
        //        public void CaptureScreenShotAndCopy(int width, int height, GameObject parent, string savePath, Camera camera)
        //        {
        //            parent.GetComponent<MonoBehaviour>().StartCoroutine(CaptureScreenShot2(width, height, parent, savePath, camera, true));
        //        }

        //        //让用户选择文件
        //        public static string SelectFile(string type)
        //        {
        //            string path = string.Empty;
        //#if !UNITY_ANDROID
        //#if !UNITY_IPHONE
        //            OpenFileDialog op = new OpenFileDialog();
        //            op.Title = "选择文件";
        //            if (type == string.Empty || type==null) { type = "图像文件(*.png)|*.png"; }
        //            op.Filter = type;// "音频文件(*.wav;*.ogg)|*.wav;*.ogg";
        //            if (op.ShowDialog()!=DialogResult.Abort)
        //            {
        //                string selectName = op.FileName;
        //                if (selectName != string.Empty) { path = selectName; }
        //                //Debug.LogError(path.ToString());
        //            }
        //            op.Dispose();
        //#endif
        //#endif
        //            return path;
        //        }



        //        //自定义文件保存文件夹;
        //        public static string SaveCutScreenPath()
        //        {
        //            string path = string.Empty;
        //#if !UNITY_ANDROID
        //#if !UNITY_IPHONE
        //            FolderBrowserDialog fb = new FolderBrowserDialog();
        //            fb.ShowNewFolderButton = true;
        //            fb.RootFolder = Environment.SpecialFolder.MyComputer;
        //            fb.SelectedPath = "C:";
        //            fb.Description = "请选择目录";
        //            fb.RootFolder = Environment.SpecialFolder.MyComputer;
        //            if (fb.ShowDialog() != DialogResult.Abort)
        //            {
        //                string selectName = fb.SelectedPath;
        //                if (selectName != string.Empty) { path = selectName; }
        //                //Debug.LogError(path);
        //            }
        //            fb.Dispose();
        //#endif
        //#endif
        //            return path;
        //        }

    }
}
